package com.hang.controller;

import com.hang.common.Result;
import com.hang.model.dto.request.ItemDetailDTO;
import com.hang.model.dto.request.ItemPageDTO;
import com.hang.model.dto.request.PersonalStaticsDTO;
import com.hang.model.dto.response.PersonalTaskVO;
import com.hang.model.vo.MemberTaskDetailVO;
import com.hang.model.vo.MemberTaskListVO;
import com.hang.service.IItemService;
import com.hang.service.IItemUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "统计管理模块")
@RestController
@RequestMapping("statistics")
@Slf4j
public class StatisticsController {
    @Resource
    private IItemUserService itemUserService;

    @Resource
    private IItemService itemService;

    @ApiOperation(value = "管理员查看项目所有成员的项目情况")
    @PostMapping("task/list")
    public Result<MemberTaskListVO> getTaskConditionInItem(
            @RequestBody @Valid ItemPageDTO itemPageDTO
    ){
        MemberTaskListVO memberTaskListVO = itemUserService.getTaskConditionInItem(itemPageDTO);
        return Result.ok(memberTaskListVO);
    }

    @ApiOperation(value = "查看项目具体成员的项目情况")
    @PostMapping("task/detail")
    public Result<MemberTaskDetailVO> getTaskDetail(
            @RequestBody @Valid ItemDetailDTO itemDetailDTO
    ){
        MemberTaskDetailVO memberTaskDetailVO = itemUserService.getTaskDetail(itemDetailDTO);
        return Result.ok(memberTaskDetailVO);
    }

    @ApiOperation(value = "用户查看自己近段时间的任务、缺陷情况【个人统计】")
    @PostMapping("person")
    public Result<List<PersonalTaskVO>> getPersonalStaticsCondition(
            @RequestBody @Valid PersonalStaticsDTO personalStaticsDTO
    ){
        List<PersonalTaskVO> personalTaskVOList = itemService.getPersonalStaticsCondition(personalStaticsDTO);
        return Result.ok(personalTaskVOList);
    }

    @ApiOperation(value = "项目经理查看近端时间的任务、缺陷清空【项目统计】")
    @GetMapping("item")
    public Result<PersonalTaskVO> getItemStaticsCondition(
            @RequestParam("itemId") @ApiParam(value = "项目id",required = true) Long itemId
    ){
        PersonalTaskVO personalTaskVOList = itemService.getItemStaticsCondition(itemId);
        return Result.ok(personalTaskVOList);
    }
}
